﻿package com.tudou.ad.track
{
    import com.tudou.ad.consts.*;
    import com.tudou.ad.interfaces.*;
    import com.tudou.track.*;

    public class NodeMap extends Object
    {
        private var _aopExtInfoNode:Array;
        private var _placardAopMap:Object;
        private var _videoAopMap:Object;
        private var _swfAopMap:Object;
        private var _bgAopMap:Object;
        private static var _ins:NodeMap;

        public function NodeMap()
        {
            return;
        }// end function

        private function initPlacard() : void
        {
            _placardAopMap = {};
            _placardAopMap[NodeLog.AD_START] = NodeLog.AD_PLACARD_START;
            _placardAopMap[NodeLog.AD_END] = NodeLog.AD_PLACARD_END;
            _placardAopMap[NodeLog.AD_SHOW_START] = NodeLog.AD_PLACARD_SHOW_START;
            _placardAopMap[NodeLog.AD_SHOW_COMPLETE] = NodeLog.AD_PLACARD_SHOW_COMPLETE;
            _placardAopMap[NodeLog.AD_FULLSCREEN_SKIP] = NodeLog.AD_PLACARD_FULLSCREEN_SKIP;
            _placardAopMap[NodeLog.AD_MULTI_NEW_SKIP] = NodeLog.AD_MULTI_SKIP;
            _placardAopMap[NodeLog.AD_FRONT_STUFF_REQUEST_START] = NodeLog.AD_PLACARD_REQUEST_START;
            _placardAopMap[NodeLog.AD_FRONT_STUFF_REQUEST_ERROR] = NodeLog.AD_PLACARD_REQUEST_ERROR;
            _placardAopMap[NodeLog.AD_FRONT_STUFF_REQUEST_TIMEOUT] = NodeLog.AD_PLACARD_REQUEST_TIMEOUT;
            _placardAopMap[NodeLog.AD_FRONT_STUFF_REQUEST_COMPLETE] = NodeLog.AD_PLACARD_REQUEST_COMPLETE;
            return;
        }// end function

        private function initVideo() : void
        {
            _videoAopMap = {};
            _videoAopMap[NodeLog.AD_START] = NodeLog.AD_FRONT_START;
            _videoAopMap[NodeLog.AD_END] = NodeLog.AD_FRONT_END;
            _videoAopMap[NodeLog.AD_SHOW_START] = NodeLog.AD_FRONT_SHOW_START;
            _videoAopMap[NodeLog.AD_SHOW_COMPLETE] = NodeLog.AD_FRONT_SHOW_COMPLETE;
            _videoAopMap[NodeLog.AD_STUFFS_REQUEST_COMPLETE] = NodeLog.AD_FRONT_IMG_BACK_REQCOMPLETED;
            _videoAopMap[NodeLog.AD_USER_SKIP] = NodeLog.AD_FRONT_VIDEO_USER_SKIP;
            _videoAopMap[NodeLog.AD_MULTI_NEW_SKIP] = NodeLog.AD_MULTI_SKIP;
            _videoAopMap[NodeLog.AD_VIDEO_REQUEST_START] = NodeLog.AD_FRONT_VIDEO_REQUEST_START;
            _videoAopMap[NodeLog.AD_VIDEO_REQUEST_ERROR] = NodeLog.AD_FRONT_VIDEO_REQUEST_ERROR;
            _videoAopMap[NodeLog.AD_VIDEO_REQUEST_TIMEOUT] = NodeLog.AD_FRONT_TIME_OUT;
            _videoAopMap[NodeLog.AD_VIDEO_REQUEST_COMPLETE] = NodeLog.AD_FRONT_VIDEO_REQUEST_COMPLETE;
            _videoAopMap[NodeLog.AD_VIDEO_URL_NULL] = NodeLog.AD_FRONT_URL_NULL;
            _videoAopMap[NodeLog.AD_VIDEO_BUFFER] = NodeLog.AD_FRONT_VIDEO_BUFFER;
            _videoAopMap[NodeLog.AD_VIDEO_LOAD_COMPLETE] = NodeLog.AD_FRONT_VIDEO_LOAD_COMPLETE;
            _videoAopMap[NodeLog.AD_VIDEO_PLAY_COMPLETE] = NodeLog.AD_FRONT_VIDEO_PLAY_COMPLETE;
            _videoAopMap[NodeLog.AD_VIDEO_PLAYHEADTIME] = NodeLog.AD_FRONT_VIDEO_PLAYHEADTIME;
            _videoAopMap[NodeLog.AD_VIDEO_BUFFER5_SKIP] = NodeLog.AD_FRONT_VIDEO_BUFFER5_SKIP;
            _videoAopMap[NodeLog.AD_VIDEO_MORE5SEC_SKIP] = NodeLog.AD_FRONT_VIDEO_MORE5SEC_SKIP;
            _videoAopMap[NodeLog.AD_FRONT_STUFF_REQUEST_START] = NodeLog.AD_FRONT_IMAGE_REQUEST_START;
            _videoAopMap[NodeLog.AD_FRONT_STUFF_REQUEST_ERROR] = NodeLog.AD_FRONT_IMAGE_REQUEST_ERROR;
            _videoAopMap[NodeLog.AD_FRONT_STUFF_REQUEST_TIMEOUT] = NodeLog.AD_FRONT_IMAGE_REQUEST_TIMEOUT;
            _videoAopMap[NodeLog.AD_FRONT_STUFF_REQUEST_COMPLETE] = NodeLog.AD_FRONT_IMAGE_REQUEST_COMPLETE;
            _videoAopMap[NodeLog.AD_BG_STUFF_REQUEST_START] = NodeLog.AD_FRONT_BG_REQUEST_START;
            _videoAopMap[NodeLog.AD_BG_STUFF_REQUEST_ERROR] = NodeLog.AD_FRONT_BG_REQUEST_ERROR;
            _videoAopMap[NodeLog.AD_BG_STUFF_REQUEST_TIMEOUT] = NodeLog.AD_FRONT_BG_REQUEST_TIMEOUT;
            _videoAopMap[NodeLog.AD_BG_STUFF_REQUEST_COMPLETE] = NodeLog.AD_FRONT_BG_REQUEST_COMPLETE;
            return;
        }// end function

        public function aopExtInfoNode(param1:String) : Boolean
        {
            return _aopExtInfoNode.indexOf(param1) !== -1 ? (true) : (false);
        }// end function

        public function getOldNodeLog(param1:IAdItemInfo, param2:String) : String
        {
            var _loc_3:* = param1.type;
            var _loc_4:String = "";
            switch(_loc_3)
            {
                case AdType.FRONT:
                case AdType.BACK:
                case AdType.PAUSE:
                {
                    if (param1.isVideo)
                    {
                        _loc_4 = _videoAopMap[param2];
                    }
                    else
                    {
                        _loc_4 = _swfAopMap[param2];
                    }
                    break;
                }
                case AdType.PLACARD:
                {
                    _loc_4 = _placardAopMap[param2];
                    break;
                }
                case AdType.BACKGROUND:
                {
                    _loc_4 = _bgAopMap[param2];
                    break;
                }
                default:
                {
                    break;
                    break;
                }
            }
            if (_loc_4)
            {
                if (AdType.FRONT == _loc_3)
                {
                    if (param1.orderPos == 1)
                    {
                        _loc_4 = "4" + _loc_4;
                    }
                    else if (param1.orderPos > 1)
                    {
                        _loc_4 = "";
                    }
                }
                else if (AdType.BACK == _loc_3)
                {
                    _loc_4 = "1" + _loc_4;
                }
                else if (AdType.PAUSE == _loc_3)
                {
                    _loc_4 = "3" + _loc_4;
                }
            }
            return _loc_4;
        }// end function

        private function initSwf() : void
        {
            _swfAopMap = {};
            _swfAopMap[NodeLog.AD_START] = NodeLog.AD_FRONT_START;
            _swfAopMap[NodeLog.AD_END] = NodeLog.AD_FRONT_END;
            _swfAopMap[NodeLog.AD_SHOW_START] = NodeLog.AD_FRONT_SWF_SHOW_START;
            _swfAopMap[NodeLog.AD_SHOW_COMPLETE] = NodeLog.AD_FRONT_SWF_SHOW_COMPLETE;
            _swfAopMap[NodeLog.AD_STUFFS_REQUEST_COMPLETE] = NodeLog.AD_FRONT_SWF_IMG_BACK_REQCOMPLETED;
            _swfAopMap[NodeLog.AD_MULTI_NEW_SKIP] = NodeLog.AD_MULTI_SKIP;
            _swfAopMap[NodeLog.AD_FRONT_STUFF_REQUEST_START] = NodeLog.AD_FRONT_SWF_IMAGE_REQUEST_START;
            _swfAopMap[NodeLog.AD_FRONT_STUFF_REQUEST_ERROR] = NodeLog.AD_FRONT_SWF_IMAGE_REQUEST_ERROR;
            _swfAopMap[NodeLog.AD_FRONT_STUFF_REQUEST_TIMEOUT] = NodeLog.AD_FRONT_SWF_IMAGE_REQUEST_TIMEOUT;
            _swfAopMap[NodeLog.AD_FRONT_STUFF_REQUEST_COMPLETE] = NodeLog.AD_FRONT_SWF_IMAGE_REQUEST_COMPLETE;
            _swfAopMap[NodeLog.AD_BG_STUFF_REQUEST_START] = NodeLog.AD_FRONT_SWF_BG_REQUEST_START;
            _swfAopMap[NodeLog.AD_BG_STUFF_REQUEST_ERROR] = NodeLog.AD_FRONT_SWF_BG_REQUEST_ERROR;
            _swfAopMap[NodeLog.AD_BG_STUFF_REQUEST_TIMEOUT] = NodeLog.AD_FRONT_SWF_BG_REQUEST_TIMEOUT;
            _swfAopMap[NodeLog.AD_BG_STUFF_REQUEST_COMPLETE] = NodeLog.AD_FRONT_SWF_BG_REQUEST_COMPLETE;
            return;
        }// end function

        private function initBg() : void
        {
            _bgAopMap = {};
            _bgAopMap[NodeLog.AD_START] = "";
            _bgAopMap[NodeLog.AD_END] = "";
            _bgAopMap[NodeLog.AD_SHOW_START] = NodeLog.AD_BACKGROUND_SHOW_START;
            _bgAopMap[NodeLog.AD_SHOW_COMPLETE] = "";
            _bgAopMap[NodeLog.AD_FRONT_STUFF_REQUEST_START] = NodeLog.AD_BACKGROUND_REQUEST_START;
            _bgAopMap[NodeLog.AD_FRONT_STUFF_REQUEST_ERROR] = NodeLog.AD_BACKGROUND_REQUEST_ERROR;
            _bgAopMap[NodeLog.AD_FRONT_STUFF_REQUEST_COMPLETE] = NodeLog.AD_BACKGROUND_REQUEST_COMPLETE;
            return;
        }// end function

        private function init() : void
        {
            initVideo();
            initSwf();
            initBg();
            initPlacard();
            _aopExtInfoNode = [NodeLog.AD_BG_STUFF_REQUEST_ERROR, NodeLog.AD_BG_STUFF_REQUEST_TIMEOUT, NodeLog.AD_FRONT_STUFF_REQUEST_ERROR, NodeLog.AD_FRONT_STUFF_REQUEST_TIMEOUT, NodeLog.AD_VIDEO_REQUEST_START, NodeLog.AD_VIDEO_REQUEST_ERROR, NodeLog.AD_VIDEO_REQUEST_TIMEOUT, NodeLog.AD_VIDEO_PLAYHEADTIME, NodeLog.AD_VIDEO_SUB_REQUEST_START, NodeLog.AD_VIDEO_SUB_REQUEST_ERROR];
            return;
        }// end function

        public static function get ins() : NodeMap
        {
            if (_ins)
            {
                return _ins;
            }
            _ins = new NodeMap;
            _ins.init();
            return _ins;
        }// end function

    }
}
